package com.zhengxiang.onlinexamination.controller;

import com.zhengxiang.onlinexamination.base.AjaxResult;
import com.zhengxiang.onlinexamination.entity.vo.PreviewPaperVo;
import com.zhengxiang.onlinexamination.service.PreviewPaperService;
import com.zhengxiang.onlinexamination.service.WaitPaperService;
import com.zhengxiang.onlinexamination.utils.SecurityUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 预考试题记录(PreviewPaper)表控制层
 *
 * @author makejava
 * @since 2023-03-19 16:34:35
 */
@RestController
@RequestMapping("previewPaper")
public class PreviewPaperController {
    /**
     * 服务对象
     */
    @Resource
    private PreviewPaperService previewPaperService;


    /**
     * 生成待考记录
     * @param previewPaperVo
     * @return
     */
    @GetMapping("/savePreviewPaper")
    public AjaxResult savePreviewPaper( PreviewPaperVo previewPaperVo){
        //判断是否已存在待考记录
        previewPaperVo.setUserId(SecurityUtils.getCustomerLoginUser().getCustomerUserId());
        if(!previewPaperService.checkWaitPaper(previewPaperVo.getUserId(),previewPaperVo.getWaitPaperId())){
            previewPaperService.savePreviewPaper(previewPaperVo);
        }
        return AjaxResult.success();
    }

    /**
     *  一题一打 打分
     * @return
     */
    @PostMapping("/calculationScore")
    public AjaxResult calculationScore(@RequestBody PreviewPaperVo previewPaperVo){
        previewPaperService.calculationScore(previewPaperVo);
        return AjaxResult.success();
    }


    /**
     * 试卷详情
     * @param ppv
     * @return
     */
    @PostMapping("/queryPaperInfo")
    public AjaxResult queryPaperInfo(@RequestBody PreviewPaperVo ppv){
        return AjaxResult.success(previewPaperService.queryPaperInfo(ppv));
    }


    /**
     * 题目信息
     * @param ppv
     * @return
     */
    @GetMapping("/queryQuInfo")
    public AjaxResult queryQuInfo( PreviewPaperVo ppv){
        return AjaxResult.success(previewPaperService.queryQuInfo(ppv));
    }

    /**
     * 获取所有待考试题
     * */
    @GetMapping("/queryNeedCheckQuestion")
    public AjaxResult queryNeedCheckQuestion( PreviewPaperVo ppv){

        return AjaxResult.success(previewPaperService.queryNeedCheckQuestion(ppv));
    }
}

